﻿using System;
using System.Numerics;
using System.Text;
using Me.Prettyprint.Cassandra.Utils;
using Me.Prettyprint.Hector.Api.Ddl;

namespace Me.Prettyprint.Cassandra.Serializers
{
    /// <summary>
    /// Note that BigDecimalSerializer doesn't handle conversion between big/little
    /// endian encoding. Instead the BigDecimal class is responsible for handling
    /// those details.
    /// </summary>
    public class BigDecimalSerializer : AbstractSerializer<System.Numerics.BigDecimal>
    {
        public static BigDecimalSerializer Instance = new BigDecimalSerializer();

        public BigDecimalSerializer()
        {
        }
        public override ComparatorType GetComparatorType()
        {
            return ComparatorType.DECIMALTYPE;
        }
        override public ComparatorType ComparatorType
        {
            get
            {
                return ComparatorType.DECIMALTYPE;
            }
        }
        public override byte[] ToBytes(System.Numerics.BigDecimal obj)
        {
            return obj.ToByteArray();
        }
        public override Utils.ByteBuffer ToByteBuffer(System.Numerics.BigDecimal obj)
        {
            return new ByteBuffer(ToBytes(obj));
        }
        public override System.Numerics.BigDecimal FromBytes(byte[] bytes)
        {
            return BigDecimal.ConvertFromBytes(bytes);
        }
        public override System.Numerics.BigDecimal FromByteBuffer(ByteBuffer buff)
        {
            return FromBytes(buff.GetBuffer());
        }
    }
}
